package com.swt.controller;

import com.swt.common.vo.ResponseVo;
import com.swt.domain.Cart;
import com.swt.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description
 * @Author swt
 * @Date 2022/5/17
 */
@RestController
@RequestMapping("/Cart")
public class CartController {
    @Autowired
    public CartService cartService;
    @GetMapping("/{count}/{size}")
    public ResponseVo pageCart(@PathVariable Integer count, @PathVariable Integer size){
        return ResponseVo.SUCCESS(cartService.pageCart(count,size));

    }
    @DeleteMapping("/{id}")
    public ResponseVo deleteCart(@PathVariable String id){
        return cartService.delectCart(id)>0?ResponseVo.SUCCESS:ResponseVo.FAIL;
    }
    @GetMapping("/{id}")
    public ResponseVo selectCartById(@PathVariable String id){
        return ResponseVo.SUCCESS(cartService.selectbyidCart(id));
    }
    @PostMapping
    public ResponseVo insertCart(@RequestBody Cart s){
        return cartService.inserCart(s)>0?ResponseVo.SUCCESS:ResponseVo.FAIL;
    }
    @PutMapping
    public ResponseVo updateCart(@RequestBody Cart s){
        return cartService.updateCart(s)>0?ResponseVo.SUCCESS:ResponseVo.FAIL;
    }
}

